package com.velocityme.client.gui.calendar;

import javax.swing.table.*;
import java.util.*;

/** 
The Table model used by the some of the calendars. This model makes use
of two vectors to store/return the data for the table.
*/
class CalendarTableModel extends AbstractTableModel {
	public CalendarTableModel() {

	}

	public void addColumn(String val) {
		colNames.addElement(val);
		//fireTableStructureChanged();
	}

	public void addRow(Object[] val) {
		Vector newRow = new Vector(7);

		for(int col = 0; col < val.length; col++) {
			if(val[col] != null) {
				newRow.addElement(val[col]);
			}		 
		}
		dataRows.addElement(newRow);
		//fireTableDataChanged();
	}

	public void clearData() {
		dataRows.clear();
		//fireTableDataChanged();
	}

	public Class getColumnClass(int col) {
		return "".getClass();
	}

	public int getColumnCount() {
		return colNames.size();
	}

	public String getColumnName(int col) {
		return colNames.get(col).toString();
	}

	public int getRowCount() {
		return dataRows.size();
	}

	public Object getValueAt(int x, int y) {        
		if(x >= dataRows.size())
			return null;
		Vector rowData = (Vector)dataRows.get(x);

		if(y >= rowData.size())
			return null;
		return rowData.get(y);
	
	}

	public void setValueAt(Object val, int row, int col) {
		if (row < 0 || row > dataRows.size())
			return;
		Vector rowData = (Vector)dataRows.get(row);
		rowData.setElementAt(val, col);
		dataRows.setElementAt(rowData, row);
		//fireTableDataChanged();
	}
	
	public boolean isCellEditable(int r, int c) {
		return false;
	}

	private Vector dataRows = new Vector(6);
	private Vector colNames = new Vector(7);
}
